package com.vinyl.sound 
{
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
	
	import com.vinyl.events.DataEvent;
	/**
	 * ...
	 * @author 
	 */
	public class SoundLoader extends EventDispatcher
	{
		public var url:String;
        private var song:SoundChannel;
		public var initFlag:Boolean = false;
		public var downloadProgresFlag:Boolean;
		public var sound:Sound;
		
		public function SoundLoader( url ) 
		{
			this.url = url;
			downloadProgresFlag = false;
		}
		
		public function load()
		{
			initFlag = true;
			
            var request:URLRequest = new URLRequest(url);
            sound = new Sound();
            sound.addEventListener(Event.COMPLETE, completeHandler);
            sound.addEventListener(Event.ID3, id3Handler);
            sound.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            sound.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            sound.load(request);
		}
		
        private function completeHandler(event:Event):void {
            //trace("completeHandler: " + event);
			dispatchEvent( new Event( Event.COMPLETE ) );
        }
		
        private function id3Handler(event:Event):void {
            //trace("id3Handler: " + event);
        }
		
        private function ioErrorHandler(event:Event):void {
            //trace("ioErrorHandler: " + event);
        }
		
        private function progressHandler(event:ProgressEvent):void {
            //trace("progressHandler: " + event);
			downloadProgresFlag = true;
        }
	}
}